package com.tg.paw.oms.config;

import com.tg.paw.oms.constants.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Rubble
 * @date 2020/6/18
 */
@Configuration
public class UmsMqConfig {

    @Autowired
    public void  rabbitProperties(RabbitProperties rabbitProperties){
        MqConstants.VIRTUAL_HOST = rabbitProperties.getVirtualHost();
    }

    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(MqConstants.DIRECT_EXCHANGE);
    }

    @Bean
    public Queue orderQueue(){
        return new Queue(MqConstants.ORDER_UMS_PAW_QUEUE);
    }

    @Bean
    public Binding bingOrderQueue(){
        return BindingBuilder.bind(orderQueue()).to(directExchange()).with(MqConstants.ORDER_UMS_PAW_ROUTING_KEY);
    }
}
